<?php
	session_start(); //因为sidebar.php 存在session_start(); 本页面若不再包含sidebar.php 则不能注销此句
if(isset($_SESSION["current_user"]))
{
	include_once("conn.php");

	$board_name = $_POST["hide_board_name"];     //所要发布帖子的版面
	$post_er = $_SESSION["current_user"];          //发表人显然必须为当前登录用户

	$post_name = $_POST["new_title"];			//帖子名
	$post_content = $_POST["new_content"];		//帖子内容


	//因为要插入帖子的数据库必须要有，t_sid,t_uid,但是我只有版面name和用户name,没有版面id和用户id，所以先SQL取出2个ID。
	$sql = "select * from bbs_user where u_name = '".$post_er."'";
	$result = mysql_query($sql);
	$q_result = mysql_fetch_array($result);
	$post_er_uid = $q_result["u_id"];                     //取的的用户id

	$sql = "select * from bbs_session where s_name = '".$board_name."'";
	$result = mysql_query($sql);
	$q_result = mysql_fetch_array($result);
	$board_id = $q_result["s_id"];						//取得的版面id
	
	date_default_timezone_set("PRC");
	$post_time = date("Y-m-d H:i:s",time());			//发表帖子的时间
	$post_week = date("D");				//星期（三字母），月份（3字母），天，年

	$sql = "insert into bbs_topic(t_sid,t_uid,t_topic,t_content,t_time,t_author,t_last_reply_name,t_session_name,t_last_reply_time,t_week) values('".$board_id."','".$post_er_uid."','".$post_name."','".$post_content."','".$post_time."','".$post_er."','".$post_er."','".$board_name."','".$post_time."','".$post_week."')";
	
	$result = mysql_query($sql);
	
}
else {
	echo "<script>alert('请先登录');window.location='index.php';</script>";
}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset=utf-8 />
</head>
<body>
<div class = "body">
	
<?php 
	if($result)
	{	
		echo "<script>alert('发表成功');</script>";
		$page = "page.php?board=".$board_name."";
		echo "<script>window.location = '".$page."'</script>";
	}
	else {
		echo "发表失败";
	}
?>

<p><strong><a href = "page.php?board=<?php echo $board_name; ?>">点此跳转回浏览版面</a></strong></p>

</div>

</body>
</html>
